package com.qxgltj.qxgl.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.qxgltj.qxgl.dao.IRolesDao;
import com.qxgltj.qxgl.dto.RolesDTO;
import com.qxgltj.qxgl.model.Roles;
import com.qxgltj.qxgl.service.IRolesService;

import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
@ApiOperation("角色列表")
@RestController
@RequestMapping(path = "/roles",method = RequestMethod.POST)
public class RolesController {
@Resource
private IRolesDao rolesDao;
@Resource
private IRolesService rolesService;
@ApiOperation(value = "查询所有角色",notes = "查询所有角色")
@GetMapping
public List<Roles> findAll(){
return rolesDao.findAll();
}
@ApiOperation(value = "查询所有",notes = "查询所有")
@GetMapping(value = "/findAll")
public Map  findAll(RolesDTO dto){
    List<Roles> list=rolesDao.findAll();
    Map<String,Object> map=new HashMap<String,Object>();
    map.put("code",0);
    map.put("count",100);
    map.put("msg","查询成功");
    map.put("data", list);
    return map;
}
@ApiOperation(value = "分页查询",notes = "分页查询")
@PostMapping("/page")
public Page findPage(@RequestBody RolesDTO dto){
    System.out.println(dto.toString());
    return rolesService.finPage(dto);
}
@ApiOperation(value = "创建角色",notes = "添加或修改")
@PostMapping("/addOrEdit")
public Roles saveRoles(@RequestBody Roles r){
    return rolesService.saveRoles(r);
}
@ApiOperation(value = "删除用户",notes = "删除用户")
@ApiImplicitParam(name = "id",value = "主键",required = true,paramType = "path")
    @DeleteMapping("/{id}")
    public void del(@PathVariable String id){
        rolesService.del(id);
    }
   @ApiOperation(value = "查询用户已有角色")
   @GetMapping(value = "/findRoles/{user_id}")
   public List<Roles> findRoles(@PathVariable String user_id){
       return rolesDao.findRoles(user_id);
   }
}